package vn.bang.entity;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
@Table(name="game")
public class GameDTO implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@Column(name="id")
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	
	@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@JoinTable(name = "game_player_attend", joinColumns = { 
			@JoinColumn(name = "game_id", nullable = false, updatable = false) }, 
			inverseJoinColumns = { @JoinColumn(name = "player_id",
					nullable = false, updatable = false) })
	private Collection<PlayerDTO> players;
	
	@ManyToOne(fetch=FetchType.LAZY, cascade = CascadeType.MERGE)
	@LazyCollection(LazyCollectionOption.TRUE)
	@JoinColumn(name="host_id")
	private PlayerDTO host;
	
	@ManyToOne(fetch=FetchType.LAZY, cascade = CascadeType.MERGE)
	@LazyCollection(LazyCollectionOption.TRUE)
	@JoinColumn(name="board_id")
	private BoardDTO board;

	public Collection<PlayerDTO> getPlayers() {
		return players;
	}

}
